package cn.edu.zufe.mjt.recursion;

/**
 * 递归问题：反转字符串
 * 给定一个字符串，要求输出其反转后的字符串
 */
public class ReverseString {
    public static void main(String[] args) {
        String str = "hello world!";
        String reversed = reverse(str);
        System.out.println(reversed);
    }

    public static String reverse(String str) {
        if (str.length() <= 1) {
            return str;
        } else {
            return reverse(str.substring(1)) + str.charAt(0);
        }
    }
}
